﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LogisticsMSDAL
{
    public class UserDAL
    {
        public bool IsAccount(string account)
        {
            string sql = "SELECT * FROM dbo.[User] WHERE Account=@acc";
            SqlParameter[] para = {
            new SqlParameter("@acc",account)
            };
            //return SQLHelper.ExecuteScalar(sql, para) == null;//如果找不到该账号  则得到true
            object res = SQLHelper.ExecuteScalar(sql, para);
            if (res != null)//账号重复
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public bool IsTel(string tel)
        {
            string sql = "SELECT * FROM dbo.[User] WHERE  Phone=@tel";
            SqlParameter[] para = {
            new SqlParameter("@tel",tel)
            };
            object res = SQLHelper.ExecuteScalar(sql, para);
            if (res != null)//手机号重复则返回false
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        public bool RegUser(string account, string tel, string pwd)
        {
            string sql = @"INSERT INTO dbo.[User](UserName,Sex,Account,Password,Phone,Email,FK_RoleID,CheckInTime,IsDelete,AlterTime)
                VALUES(   '', 0,  @acc, @pwd, @tel, '', 1, GETDATE(),0, GETDATE())";
            SqlParameter[] para = {
                 new SqlParameter("@acc",account),
            new SqlParameter("@tel",tel),
             new SqlParameter("@pwd",pwd),
            };
            int res = SQLHelper.ExecuteNonQuery(sql, para);
            return res > 0;//大于0  得到true   注册成功
        }
    }
}
